/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.zjdt.epserver.db.dao4mysql;

import com.zjdt.epserver.db.dao.TripDao;
import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 *
 * @author dusin
 */
public class TripDaoImpl implements TripDao{
    
    static Logger logger = Logger.getLogger(TripDaoImpl.class);
    private JdbcTemplate jdbcTemplate;

    public TripDaoImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }   
    @Override
    public boolean doCreate(String driverID, String plateNo, String startTime, String factoryCode) {
        boolean flag = true;
        String sql = null;
        sql = "insert into atrip(dirverId,plateNo,startTime,fcode) values(?,?,?,?)";
        int rows = jdbcTemplate.update(sql, new Object[]{driverID,plateNo,startTime,factoryCode});
        if (rows <= 0) {
            flag = false;
        }
        return flag;
    }

    @Override
    public boolean stop(int id, String stopTime) {
        boolean flag = true;
        String sql = null;
        sql = "update atrip set stopTime=?  where id=?";
        int rows = jdbcTemplate.update(sql, stopTime,id);
        if (rows <= 0) {
            flag = false;
        }
        return flag;
    }
    
    @Override
    public boolean setStatus(String rid, int status) {
        boolean flag = true;
        String sql = null;
        sql = "update atrip set status=?  where rid=?";
        int rows = jdbcTemplate.update(sql, status,rid);
        if (rows <= 0) {
            flag = false;
        }
        return flag;
    }

    @Override
    public boolean doDeleteById(int id) {
        boolean flag = true;
        String sql = null;
        sql = "delete from atrip where id=?";
        int rows = jdbcTemplate.update(sql, id);
        if (rows <= 0) {
            flag = false;
        }
        return flag;
    }

    @Override
    public Map<String, Object> findLatestLocation(int driverId) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }    
    
    
}
